<#include "/generation-templates/directive/field-type.ftl"/>
<#include "/generation-templates/directive/field-comment.ftl"/>
package ${package};

import com.ilxqx.framework.system.form.UpdateForm;
<#list table.getFields() as field>
<#if field.getRules().match("enum")>
import ${field.getType().getName()};
</#if>
</#list>
import com.ilxqx.framework.system.form.anno.Pk;
<#if basePackage != "com.ilxqx.framework.system">
import com.ilxqx.framework.system.service.impl.*;
</#if>
import ${basePackage}.service.impl.*;
import com.ilxqx.framework.system.validator.anno.*;
import com.ilxqx.framework.system.validator.group.FrameworkGroups;
import lombok.Data;

import javax.validation.constraints.*;

/**
 * ${table.getComment()}更新表单类
 * @author venus
 */
<#if table.getRules().match("multiUnique")>
@MultiFieldsUnique(<#if table.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif table.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "<#list table.getRules().getRule("multiUnique").getParam("fields")?split("-") as val><@fieldComment tableInfo = table userName = val ; comment>${comment}</@fieldComment><#sep>、</#list>{multiUnique}", service = ${table.getRules().getRule("multiUnique").getParam("service")}.class, method = "<#if table.getRules().getRule("multiUnique").getParam("method")?has_content>${table.getRules().getRule("multiUnique").getParam("method")}<#else><#list table.getRules().getRule("multiUnique").getParam("fields")?split("-") as val><#if val?is_first>${val}<#else>${val?cap_first}</#if><#sep>And</#list>Exists</#if>", fields = { <#list table.getRules().getRule("multiUnique").getParam("fields")?split("-") as val>"${val}"<#sep>, </#list> })
</#if>
<#list table.getFields() as field>
<#if field.getRules().match('form')>
<#-- 唯一规则 -->
<#if field.getRules().match("unique")>
@Unique(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{unique}", service = ${field.getRules().getRule("unique").getParam("service")}.class, method = "<#if field.getRules().getRule("unique").getParam("method")?has_content>${field.getRules().getRule("unique").getParam("method")}<#else>${field.getLowerCamelName()}Exists</#if>", field = "${field.getLowerCamelName()}")
</#if>
</#if>
</#list>
@Data
public class ${table.getCamelName()}UpdateForm implements UpdateForm {

	<#list table.getFields() as field>
	<#-- 主键字段 -->
	<#if field.isPrimaryKey()>
	/**
	 * ${field.getComment()}
	 */
	@Pk
	@NotNull(groups = FrameworkGroups.Modify.class, message = "${field.getComment()}{required}")
	@Positive(groups = FrameworkGroups.Modify.class, message = "${field.getComment()}{positive}")
	private ${field.getType().getSimpleName()} ${field.getLowerCamelName()};

	<#else>
	<#-- 表单字段判断 -->
    <#if field.getRules().match('form')>
	/**
	 * ${field.getComment()}
	 */
	<#-- 分字符串类型和非字符串类型 -->
	<#if field.getType().getSimpleName() == "String">
	<#-- 字符串类型 -->
	<#if !field.isNullable()>
	@NotBlank(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{required}")
	</#if>
	<#if field.getRules().match("length")>
	@Size(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>max = ${field.getRules().getRule("length").getParam("max")!field.getSize()}, min = ${field.getRules().getRule("length").getParam("min")!field.getSize()}, message = "${field.getComment()}{size}")
	<#else>
	@Size(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>max = ${field.getSize()}, message = "${field.getComment()}{size}")
	</#if>
	<#else>
	<#-- 非字符串类型 -->
	<#if !field.isNullable()>
	@NotNull(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{required}")
	</#if>
	<#-- 判断是否非负 -->
	<#if field.isUnsigned() && (field.getType().getSimpleName() == "Integer" || field.getType().getSimpleName() == "Long")>
	@PositiveOrZero(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{positiveOrZero}")
	</#if>
	</#if>
	<#-- 自定义规则 -->
	<#if field.getRules().match("exists")>
	@Exists(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{notExist}", service = ${field.getRules().getRule("exists").getParam("target")}.class)
	</#if>
	<#-- 邮箱 -->
	<#if field.getRules().match("email")>
	@com.ilxqx.framework.system.validator.anno.Email(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{email}")
	</#if>
	<#-- 数字 -->
	<#if field.getRules().match("digits")>
	@Digits(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{digits}")
	</#if>
	<#-- 字母 -->
	<#if field.getRules().match("alpha")>
	@Alpha(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{alpha}")
	</#if>
	<#-- 字母数字 -->
	<#if field.getRules().match("alphaNum")>
	@AlphaNum(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{alphaNum}")
	</#if>
	<#-- 字母数字下划线 -->
	<#if field.getRules().match("alphaNumDash")>
	@AlphaNumDash(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{alphaNumDash}")
	</#if>
	<#-- 汉字 -->
	<#if field.getRules().match("chinese")>
	@Chinese(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{chinese}")
	</#if>
	<#-- 身份证 -->
	<#if field.getRules().match("identity")>
	@Identity(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{identity}")
	</#if>
	<#-- 路径 -->
	<#if field.getRules().match("path")>
	@Path(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{path}")
	</#if>
	<#-- 手机号码 -->
	<#if field.getRules().match("phone")>
	@Phone(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{phone}")
	</#if>
	<#-- 邮政编码 -->
	<#if field.getRules().match("postcode")>
	@Postcode(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{postcode}")
	</#if>
	<#-- url -->
	<#if field.getRules().match("url")>
	@Url(<#if field.getRules().match("createOnly")>groups = FrameworkGroups.Create.class, <#elseif field.getRules().match("modifyOnly")>groups = FrameworkGroups.Modify.class, </#if>message = "${field.getComment()}{url}")
	</#if>
	private ${field.getType().getSimpleName()} ${field.getLowerCamelName()};

    </#if>
	</#if>
    </#list>
}
